define(['angular'], function (angular) {

/*-----------------------------------------
 *   系统服务
 ------------------------------------------*/
angular.module('books.service.system', [])
    .constant('systemServiceConfig', {
    	files:{
        	loadMenuTree:'app/data/tree/menuTree.json',
            loginFun:'app/data/login.json',//登录
            logoutFun:'app/data/logout.json'//登n
        },
        urls:{
        	loadMenuTree:'system/retrSysCodes.do',//sysCode查询
            loginFun:'http://47.92.95.246:8012/login',//登录
            logoutFun:'http://47.92.95.246:8012/logout'//登出
        }
    })
    .factory('systemService',['$http', '$q', 'systemServiceConfig', function ($http, $q, systemServiceConfig) {
        return {
            //加载tree josn 数据
            loadMenuTree: function(){
                var deffered = $q.defer();//内置服务 同步请求数据
                //请求数据
                $http({
                    method:'POST',
                    dataType: "json",
                    contentType:'application/json; charset=UTF-8',
                    // url:'app/data/tree/menuTree.json'//json 路径
                    url:systemServiceConfig.files.loadMenuTree,
                })
                .success(function(response){
                    deffered.resolve(response);
                })
                .error(function(e, code){
                    deffered.reject(code);
                });
                return deffered.promise;    
            },

        	/**
        	 * 登录
        	 * 
        	 * @param usercode
        	 * @param password
        	 * @return
        	 */
        	loginFun:function(usercode,password){
        		var deffered = $q.defer();//内置服务 同步请求数据
                //请求数据
                $http({
                    method:'POST',
                    dataType: "json",
                    contentType:'application/json; charset=UTF-8',
                    url:systemServiceConfig.urls.loginFun,
                    params:{
                    	name : usercode,
                    	pass : password
                    }
                })
                .success(function(response){
                    deffered.resolve(response);
                })
                .error(function(e, code){
                    deffered.reject(code);
                });
                return deffered.promise;    
        	},
        	/**
        	 * 登出
        	 * @return
        	 */
            logoutFun:function(){
            	var deffered = $q.defer();//内置服务 同步请求数据
                //请求数据
                $http({
                    method:'POST',
                    dataType: "json",
                    contentType:'application/json; charset=UTF-8',
                    url:systemServiceConfig.urls.logoutFun
                })
                .success(function(response){
                    deffered.resolve(response);
                })
                .error(function(e, code){
                    deffered.reject(code);
                });
                return deffered.promise; 
            }
        };
    }]);

});
